﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Animation;

namespace MyAnimelistRecommender.Controls
{
    /// <summary>
    /// Interaction logic for BusyIndicator.xaml
    /// </summary>
    public partial class BusyIndicator : UserControl
    {
        public BusyIndicator()
        {
            InitializeComponent();
        }

        private static void RaiseIsBusyChanged(DependencyObject _do, DependencyPropertyChangedEventArgs e)
        {
            if ((bool)e.NewValue)
            {
                ((Storyboard)((BusyIndicator)_do).Resources["IsBusyBeginStoryboard"]).Begin();
            }
            else
            {
                ((Storyboard)((BusyIndicator)_do).Resources["IsBusyBeginStoryboard"]).Pause();
            }
        }

        public static readonly DependencyProperty IsBusyProperty = DependencyProperty.Register("IsBusy", typeof(Boolean), typeof(BusyIndicator), new PropertyMetadata(false, new PropertyChangedCallback(RaiseIsBusyChanged)));

        public bool IsBusy
        {
            get { return (bool)GetValue(IsBusyProperty); }
            set { SetValue(IsBusyProperty, value); }
        }
    }
}